package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);
    // 新增菜品

    //插入菜品数据
    //@AutoFill(value = OperationType.INSERT)
    void savedish(Dish dish);


    // 批量插入口味数据
    void saveFlavor(List<DishFlavor> flavors);

    // 根据菜品id查询菜品数据
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    // 根据id删除菜品数据
    @Delete("delete from dish where id=#{id}")
    void deletedish(Long id);

    // 根据id删除对应的口味数据
    @Delete("delete from dish_flavor where dish_id=#{id}")
    void deletedishFlavor(Long id);


    @Update("update dish set status = #{status} where id = #{id}")
    void updateqt(Dish dish);

    void update(Dish dish);

    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> getByDishId(Long id);


    @Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<Dish> list(Long categoryId);


//  @Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<Dish> list1(Dish dish);
}
